package com.lmb.controller;

import com.lmb.bean.Residents;
import com.lmb.mapper.ResidentsDao;
import com.lmb.service.ResidentsService;
import com.lmb.util.Page;
import com.lmb.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin //允许跨域访问
@RequestMapping("/residents")
public class ResidentsController {
    @Autowired
    ResidentsDao residentsDao;
    @Autowired
    ResidentsService residentsService;
    @PostMapping
    public Result add(@RequestBody Residents residents)
    {
        Object obj=residentsService.add(residents);
        return Result.success("添加保存成功",obj);
    }
    @DeleteMapping("{id}")
    public Result del(@PathVariable("id") Integer id){
        Object obj=residentsService.del(id);
        return Result.success("删除成功",obj);
    }
    @PutMapping
    public Result edit(@RequestBody Residents residents){
        Object obj=residentsService.edit(residents);
        return Result.success("信息修改成功",obj);
    }
    @GetMapping("all")
    public Result all( Residents residents){
        Object obj=residentsService.all(residents);
        return Result.success(obj);
    }
    @GetMapping("{id}")
    public Result one(@PathVariable("id") Integer id){
        Object obj=residentsService.one(id);
        return Result.success(obj);
    }
    @GetMapping("page")
    public Result page(Page page, Residents residents){
        residentsService.page(page,residents);
        return Result.success(page);
    }
}
